﻿<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.lmpop.trade.ti_custcomment.Ti_custcommentInfo"%>

<%!
	public boolean isExistCookie(HttpServletRequest request,String info_id){
		Cookie   cookies[]=request.getCookies();
		Cookie   sCookie=null;
		String   svalue=null;
		String   sname=null;
		boolean isExist = false;
		if(cookies!=null && cookies.length>0){
		   for(int a=0;a<cookies.length;a++){
				String name = cookies[a].getName();
				String value = cookies[a].getValue();
				if(!name.equals("") && name.equals(info_id)){
					isExist = true;
				}
		   }
		}
		return isExist;
	}
%>
	
<%
	Ti_custcommentInfo comm = new Ti_custcommentInfo();
	int up_num=0,down_num=0;
	if(request.getParameter("up_num")!=null && !request.getParameter("up_num").equals("")){
		up_num = Integer.parseInt(request.getParameter("up_num"));
	}
	if(request.getParameter("down_num")!=null && !request.getParameter("down_num").equals("")){
		down_num = Integer.parseInt(request.getParameter("down_num"));
	}
	String info_id="",spanid="";
	if(request.getParameter("info_id")!=null){
		info_id = request.getParameter("info_id");
	}
	if(request.getParameter("spanid")!=null){
		spanid = request.getParameter("spanid");
	}

	if(isExistCookie(request,info_id)){
		comm.updateCommentNum(info_id,0,0);
	}else{
		comm.updateCommentNum(info_id,up_num,down_num);
		if(up_num!=0 || down_num!=0){
			Cookie cookie = new Cookie(info_id, info_id);
			cookie.setMaxAge(60*60*24*3);
			cookie.setPath("/");
			response.addCookie(cookie);
		}
	}

	List infoList = comm.getListByPk(info_id);
	if(infoList!=null && infoList.size()>0){
		Hashtable infoMap = (Hashtable)infoList.get(0);
		String _up_num = "",_down_num="";
		if(infoMap.get("up_num")!=null){
			_up_num = infoMap.get("up_num").toString();
		}
		if(_up_num.equals("")){
			_up_num = "0";
		}
		if(infoMap.get("down_num")!=null){
			_down_num = infoMap.get("down_num").toString();
		}
		if(_down_num.equals("")){
			_down_num = "0";
		}
		out.println("&nbsp;同意数：<a href='javascript:setCommentNum(\""+spanid+"\",\""+info_id+"\",1,0);'>["+_up_num+"]</a>&nbsp;反对数：<a href='javascript:setCommentNum(\""+spanid+"\",\""+info_id+"\",0,1);'>["+_down_num+"]</a>");
	}

%>